package com.lwy.redis;


import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {


    @Value(value = "${spring.redis.redisson.config.singleServerConfig.address}")
    private String address;
    @Value(value = "${spring.redis.redisson.config.singleServerConfig.password}")
    private String password;
    @Value(value = "${spring.redis.redisson.config.singleServerConfig.database}")
    private int database;
    @Value(value = "${spring.redis.redisson.config.singleServerConfig.connectionMinimumIdleSize}")
    private int connectionMinimumIdleSize;

    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.setTransportMode(TransportMode.NIO);
        SingleServerConfig singleServerConfig = config.useSingleServer();
        singleServerConfig.setAddress(address);
        singleServerConfig.setDatabase(database);
        singleServerConfig.setConnectionMinimumIdleSize(connectionMinimumIdleSize);
        singleServerConfig.setPassword(password);
        return Redisson.create(config);
    }

}
